package com.lee.lease.web.app.controller.apartment;

import com.lee.lease.common.result.Result;
import com.lee.lease.common.threadlocal.LoginUserContext;
import com.lee.lease.common.util.JwtUtil;
import com.lee.lease.model.entity.ViewAppointment;
import com.lee.lease.web.app.service.ViewAppointmentService;
import com.lee.lease.web.app.vo.apartment.AppointmentDetailVo;
import com.lee.lease.web.app.vo.appointment.ViewAppointmentVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: ViewAppointmentController
 * Package: com.lee.lease.web.app.controller.user
 * Description:
 */
@Tag(name = "看房预约信息")
@RestController("ViewAppointmentController2")
@RequestMapping("/app/appointment/")
public class ViewAppointmentController {
    @Autowired
    private ViewAppointmentService service;

    @Operation(summary = "保存或更新看房预约")
    @PostMapping("saveOrUpdate")
    public Result saveOrUpdate(@RequestBody ViewAppointment viewAppointment){
        Long userId = LoginUserContext.getLoginUser().getUserId();
        viewAppointment.setUserId(userId);
        service.saveOrUpdate(viewAppointment);
        return Result.ok();
    }


    @Operation(summary = "查询看房列表")
    @GetMapping("listItem")
    public Result<List<ViewAppointmentVo>> listItem(@RequestHeader("access_token")String token){
        Integer userId = JwtUtil.parseToken(token).get("userId", Integer.class);
        List<ViewAppointmentVo> viewAppointmentVoList = service.findListItem(userId);
        return  Result.ok(viewAppointmentVoList);

    }

    @Operation(summary = "根据id查询预约详情")
    @GetMapping("/getDetailById")
    public Result<AppointmentDetailVo> getDetailById(String id){
        AppointmentDetailVo appointmentDetailVo = service.getDetailById(id);
        return Result.ok(appointmentDetailVo);
    }

}
